package com.wq.rentHouse.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wq.rentHouse.entity.HouseEntity;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wq.common.utils.PageUtils;
import com.wq.common.utils.Query;

import com.wq.rentHouse.dao.UserDao;
import com.wq.rentHouse.entity.UserEntity;
import com.wq.rentHouse.service.UserService;


@Service("userService" )
public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements UserService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        final String key = (String) params.get("key" );
        final LambdaQueryWrapper<UserEntity> lqw = new LambdaQueryWrapper<>();
        lqw.eq(UserEntity::getDisplay, 1);
        if (key != "" ) {
            lqw.eq(UserEntity::getId, key).or().like(UserEntity::getName, key);

            if ("管理员".contains(key)) {
                lqw.or().eq(UserEntity::getCategory, 0);
            } else if ("房东".contains(key)) {
                lqw.or().eq(UserEntity::getCategory, 1);
            } else if ("租客".contains(key)) {
                lqw.or().eq(UserEntity::getCategory, 2);
            }
        }

        IPage<UserEntity> page = this.page(new Query<UserEntity>().getPage(params), lqw);
        return new PageUtils(page);
    }

}
